package eli.turchinsky.software.agame.hood;

import java.util.List;

import eli.turchinsky.software.agame.IUpdatableAndDrawable;
import eli.turchinsky.software.agame.enteties.*;

import android.graphics.Canvas;

public class Gravity implements IUpdatableAndDrawable{
	List<GameEntety> _ges;
	public Gravity(List<GameEntety> geList){
		_ges=geList;
	}
	public void init() {	}

	public void draw(Canvas canvas) {	
	}

	public void update(long gameTime) {		
		for(GameEntety e:_ges){
			Star touching=null;
			if(!(e instanceof Star)){
				
				for(GameEntety star:_ges){
					if(star instanceof Star){
						if(!e.isCircleColide(star)){
							//Change this later:
							float speed=2f;
							Vector2 ad=e.getCenterPos().angleDifNeg(star.getCenterPos());
							e.getVelocity().set(ad.getX()*speed,ad.getY()*speed);							
						}
						else{							
							e.getVelocity().set(0, 0);
							e.setCenterPos( star.getCenterPos().addNew(  e.getCenterPos().angleDif(star.getCenterPos()).mul(2*star.getWidth() / 2.75f)));
							touching=(Star)star;
						}
					}
				}
			}
			e.setTouchingStar(touching);
		}
	}

}
